<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f2f5;
        }

        .login-container {
            background: white;
            padding: 40px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            width: 320px;
        }

        h2 {
            text-align: center;
            color: #1a73e8;
            margin-bottom: 30px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        input[type="text"],
        input[type="password"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }

        .options {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            font-size: 14px;
        }

        .remember-me {
            display: flex;
            align-items: center;
        }

        .remember-me input {
            margin-right: 5px;
        }

        .actions {
            display: flex;
            justify-content: space-between;
        }

        button {
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
        }

        .login-btn {
            background-color: #1a73e8;
            color: white;
        }

        .register-btn {
            background-color: #34a853;
            color: white;
        }

        a {
            color: #1a73e8;
            text-decoration: none;
            cursor: pointer;
        }

        a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div class="login-container">
        <h2>用户登录</h2>
        <form id="loginForm">
            <div class="form-group">
                <input type="text" id="username" placeholder="请输入账号" required>
            </div>
            <div class="form-group">
                <input type="password" id="password" placeholder="请输入密码" required>
            </div>
            <div class="options">
                <label class="remember-me">
                    <input type="checkbox" id="rememberMe"> 记住密码
                </label>
                <a onclick="handleForgetPassword()">忘记密码？</a>
            </div>
            <div class="actions">
                <button type="submit" class="login-btn">登录</button>
                <button type="button" class="register-btn" onclick="handleRegister()">注册</button>
            </div>
        </form>
    </div>

    <script>
        // 页面加载时检查本地存储
        document.addEventListener('DOMContentLoaded', () => {
            const rememberedUser = localStorage.getItem('rememberedUser');
            if (rememberedUser) {
                const user = JSON.parse(rememberedUser);
                document.getElementById('username').value = user.username;
                document.getElementById('password').value = user.password;
                document.getElementById('rememberMe').checked = true;
            }
        });

        // 处理表单提交
        document.getElementById('loginForm').addEventListener('submit', (e) => {
            e.preventDefault();
            
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            const rememberMe = document.getElementById('rememberMe').checked;

            // 简单验证
            if (!username || !password) {
                alert('请输入账号和密码！');
                return;
            }

            // 处理记住密码功能
            if (rememberMe) {
                localStorage.setItem('rememberedUser', JSON.stringify({
                    username,
                    password
                }));
            } else {
                localStorage.removeItem('rememberedUser');
            }

            // 这里可以添加实际的登录逻辑
            alert('登录成功！');
            // window.location.href = '/dashboard'; // 实际登录成功后跳转
        });

        // 处理忘记密码
        function handleForgetPassword() {
            const email = prompt('请输入注册邮箱：');
            if (email) {
                // 这里可以添加发送重置密码邮件的逻辑
                alert('重置链接已发送至您的邮箱，请查收！');
            }
        }

        // 处理注册
        function handleRegister() {
            // 这里可以跳转到注册页面
            alert('跳转到注册页面...');
            // window.location.href = '/register';
        }
    </script>
</body>
</html>